using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using PickGold.Charting.Utilities;

namespace PickGold.Charting.Design
{
	internal class ColorPaletteEditor : UITypeEditor
	{
		public override bool GetPaintValueSupported(ITypeDescriptorContext context)
		{
			return true;
		}

		public override void PaintValue(PaintValueEventArgs e)
		{
			var palette = (ChartColorPalette)e.Value;
			if (palette == ChartColorPalette.None)
			{
				base.PaintValue(e);
			}
			else
			{
				var paletteColors = ChartPaletteColors.GetPaletteColors(palette);
				int length = paletteColors.Length;
				if (length > 6)
				{
					length = 6;
				}
				int num2 = paletteColors.Length / length;
				RectangleF bounds = e.Bounds;
				bounds.Width = ((float)e.Bounds.Width) / ((float)length);
				for (int i = 0; i < length; i++)
				{
					if (i == (length - 1))
					{
						bounds.Width = e.Bounds.Right - bounds.X;
					}
					e.Graphics.FillRectangle(new SolidBrush(paletteColors[i * num2]), bounds);
					bounds.X = bounds.Right;
					bounds.Width = ((float)e.Bounds.Width) / ((float)length);
				}
			}
		}
	}
}

